/**
 * @param {Egg.Application} app - egg application
 */

module.exports = app => {
  const { router, controller, middleware  } = app; 
  const _jwt = middleware.jwtErr(app.config.jwt.secret); // 传入加密字符串
  router.get('/', controller.home.index);

  // 上传头像
  // router.post('/api/upload/avatar', _jwt, controller.upload.uploadAvatar);
  router.post('/api/upload/avatar', controller.upload.uploadAvatar);

  router.post('/api/user/login', controller.user.userLogin);
  router.post('/api/user/register', controller.user.register);
  router.get('/api/user/get_userinfo', _jwt, controller.user.getUserInfo); // 获取用户信息

  router.post('/api/admin/login', controller.admin.adminLogin);
  router.post('/api/admin/register', controller.admin.register);
  router.get('/api/admin/get_userinfo', _jwt, controller.admin.getAdminInfo); // 获取管理员信息


  router.post('/api/category/add', _jwt, controller.category.newCategory); // 创建分类
  router.post('/api/category/delete', _jwt, controller.category.deleteCategory); // 删除分类
  router.post('/api/category/update', _jwt, controller.category.updateCategory); // 更新分类
  router.get('/api/category/list', _jwt, controller.category.getCategoryList); // 获取分类列表
  router.get('/api/category/detail', _jwt, controller.category.getCategoryDetail); // 获取分类详情

  router.post('/api/tags/add', _jwt, controller.tags.newTags); // 创建标签
  router.post('/api/tags/delete', _jwt, controller.tags.deleteTags); // 删除标签
  router.post('/api/tags/update', _jwt, controller.tags.updateTags); // 更新标签
  router.get('/api/tags/list', _jwt, controller.tags.getTagsList); // 获取标签列表
  router.get('/api/tags/detail', _jwt, controller.tags.getTagsDetail); // 获取标签详情

  router.post('/api/article/add', _jwt, controller.article.newArticle); // 创建文章
  router.post('/api/article/delete', _jwt, controller.article.deleteArticle); // 删除文章
  router.post('/api/article/update', _jwt, controller.article.updateArticle); // 更新文章
  router.get('/api/article/list', _jwt, controller.article.getArticleList); // 获取文章列表
  router.get('/api/article/detail', _jwt, controller.article.getArticleDetail); // 获取文章详情
};
